﻿using UnityEngine;
using UnityEditor;

namespace BehaviorSystem
{
    /// <summary>
    /// 平行节点
    /// </summary>
    public class ParallelNode : CompositeNode
    {
        BTNodeState tempNodeState;
        bool isAllRuned;
        public ParallelNode(IBehaviorAgent agent) : base(agent)
        {
        }

        public override BTNodeState HandleComposite()
        {
            isAllRuned = true;
            for (int i = 0; i < ChildrenNodes.Count; i++)
            {
                ChildrenNodes[i].ExcuteNode();
                if (ChildrenNodes[i].CurState == BTNodeState.Running)
                {
                    isAllRuned = false;
                }
            }
            if (isAllRuned)
            {
                CurState = BTNodeState.Success;
            }
            else
            {
                CurState = BTNodeState.Running;
            }
            return CurState;
        }
    }
}